package com.larissa.quiz;

import android.util.Log;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class QuestionViewModel extends ViewModel {
    private static final String TAG="QuestionListViewModel";
    private QuizRepository repository;
    public LiveData<List<Question>> questionsLiveData;
    private MutableLiveData<UUID>questionIdLiveData=new MutableLiveData<UUID>();
    public LiveData<Question>questionLiveData= Transformations.switchMap(questionIdLiveData,id-> repository.getQuestionById(id));

    public QuestionViewModel(){
        repository=QuizRepository.getInstance();
        questionsLiveData=repository.getQuestions();
    }

    public void loadQuestion(UUID id){
        questionIdLiveData.setValue(id);
    }

    public void updateQuestion(Question question){
        repository.updateQuestion(question);
    }

}
